﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CarbonExchange.Bll;

namespace CarbonExchange.Tests
{
    [TestClass]
    public class AmeeProfileTests : BaseTest
    {
        [TestMethod]
        public void AmeeProfile_GetByKey_WithIncorrectKey_ReturnsNull()
        {
            AmeeProfileFactory factory = new AmeeProfileFactory();
            Assert.IsNull(factory.GetById("rubbish"));
        }
         
        [TestMethod]
        public void AmeeProfile_GetById_WithCorrectKey_ReturnsNotNull()
        {
            AmeeProfileFactory factory = new AmeeProfileFactory();
            Assert.IsNotNull(factory.GetById("3AEE24073A74"));
        }

        [TestMethod]
        public void AmeeProfile_GetById_PopulatesCorrectly()
        {
            AmeeProfileFactory factory = new AmeeProfileFactory();
            AmeeProfile tmp = factory.GetById("3AEE24073A74");
            Assert.AreEqual("3AEE24073A74", tmp.Id);
            Assert.AreEqual(1, tmp.PeopleInHoushold);
            Assert.AreEqual(DateTime.Parse("1/11/2008"), tmp.StartDate);
            Assert.AreEqual("Country 0", tmp.Country);
            Assert.AreEqual("State 0", tmp.State);
            Assert.AreEqual(5, tmp.PeopleInHoushold);
        }

        [TestMethod]
        public void AmeeProfile_UpdateOne()
        {
            AmeeProfileFactory factory = new AmeeProfileFactory();
            AmeeProfile tmp = factory.GetById("3AEE24073A74");
            Assert.IsNotNull(tmp);

            var tmpMetaDataId = tmp.MetaDataId;

            tmp.PeopleInHoushold = 10;
            tmp.StartDate = DateTime.Parse("24/10/1975");
            tmp.Country = "United Kingdom 1";
            tmp.State = "State";

            factory.Save(tmp);

            Assert.AreEqual("3AEE24073A74", tmp.Id);
            Assert.AreEqual("United Kingdom 1", tmp.Country);
            Assert.AreEqual("State", tmp.State);
            Assert.AreEqual(tmpMetaDataId, tmp.MetaDataId);
            Assert.AreEqual(10, tmp.PeopleInHoushold);
            Assert.AreEqual(DateTime.Parse("24/10/1975"), tmp.StartDate);
            
            tmp = factory.GetById("3AEE24073A74");

            Assert.AreEqual("3AEE24073A74", tmp.Id);
            Assert.AreEqual("United Kingdom 1", tmp.Country);
            Assert.AreEqual("State", tmp.State);
            Assert.AreEqual(tmpMetaDataId, tmp.MetaDataId);
            Assert.AreEqual(10, tmp.PeopleInHoushold);
            Assert.AreEqual(DateTime.Parse("24/10/1975"), tmp.StartDate);
        }

        [TestMethod]
        public void AmeeProfile_InsertOne()
        {
            AmeeProfileFactory factory = new AmeeProfileFactory();
            AmeeProfile tmp = new AmeeProfile();

            tmp.PeopleInHoushold = 10;
            tmp.StartDate = DateTime.Parse("24/10/1975");
            tmp.Country = "United Kingdom 1";
            tmp.State = "State";

            factory.Save(tmp);

            Assert.IsFalse(string.IsNullOrEmpty(tmp.Id));
            Assert.IsFalse(string.IsNullOrEmpty(tmp.MetaDataId));
            Assert.AreEqual("United Kingdom 1", tmp.Country);
            Assert.AreEqual("State", tmp.Country);
            Assert.AreEqual(10, tmp.PeopleInHoushold);
            Assert.AreEqual(DateTime.Parse("24/10/1975"), tmp.StartDate);

            string id = tmp.Id;
            string metaId = tmp.MetaDataId;

            tmp = factory.GetById(id);

            Assert.AreEqual(tmp.Id, tmp.Id);
            Assert.AreEqual("United Kingdom 1", tmp.Country);
            Assert.AreEqual("State", tmp.Country);
            Assert.AreEqual(tmp.MetaDataId, tmp.MetaDataId);
            Assert.AreEqual(10, tmp.PeopleInHoushold);
            Assert.AreEqual(DateTime.Parse("24/10/1975"), tmp.StartDate);
        }

        [TestMethod]
        public void AmeeProfile_DeleteOne()
        {
            AmeeProfileFactory factory = new AmeeProfileFactory();
            AmeeProfile tmp = factory.GetById("0E2BE62F1674");

            Assert.IsNotNull(tmp);

            factory.Delete(tmp);

            tmp = factory.GetById("0E2BE62F1674");

            Assert.IsNull(tmp);
        }
    }
}
